package com.it.design.withOutAdapterMode;

/*
 * 适配器模式
 *   使用场景：项目在更新迭代
 *         但是在迭代过程中，有一个老接口，由于这个老接口的代码规范不符合现在的代码规范
 *         所以现在的问题是，只能选择对老代码接口推到重来或者对老接口风格进行替换
 *         替换成新代码风格
 *
 *
 *
 * */
public class WithOutAdapterMode {

    public static void main(String[] args) {

        Adapter adapter = new Adapter(new OldinterfaceImpl());
        adapter.newExecute();
    }

    //适配器
    public static class Adapter implements NewInterface {
        private OldInterface oldInterface;
        public Adapter(OldInterface oldInterface) {
            this.oldInterface = oldInterface;
        }

        @Override
        public void newExecute() {
            oldInterface.oldExecute();
        }
    }

    //老代码风格接口
    public interface OldInterface {
        void oldExecute();
    }

    public static class OldinterfaceImpl implements OldInterface {

        @Override
        public void oldExecute() {
            System.out.println("我是老代码风格的oldinterface");
        }
    }

    //新代码风格接口
    public interface NewInterface {
        void newExecute();
    }

    public static class NewInterfaceImpl implements NewInterface {
        private OldInterface oldinterface;

        public NewInterfaceImpl(OldInterface oldinterface) {
            this.oldinterface = oldinterface;
        }

        @Override
        public void newExecute() {
            System.out.println("我是新代码风格的newinterface");
        }
    }
}
